package com.design.pattern.state;

import com.design.pattern.state.common.RoomAuth;
import com.design.pattern.state.common.RoomAuthStatusHandlerUtils;
import com.design.pattern.state.common.UserRoomStateFactory;
import com.design.pattern.state.domain.ChatRoom;
import com.design.pattern.state.domain.User;

/**
 * 处理用户具体访问房间权限的类
 */
public class UserRoomContext {
    private RoomAuth state;//用户权限
    private ChatRoom room;//房间
    private User user;//用户
    public UserRoomContext(ChatRoom room ,User user) {
        this.room=room;
        this.user=user;
        this.state = RoomAuthStatusHandlerUtils.getStatus(room,user);
    }
    public void login(){
        UserRoomStateFactory.createStateHandler(state).handler(room,user,this);
    }
}
